package com.blog.validation;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tcj
 * @date 2020/10/13 17:23
 */
public class ValidationUtil {
    public  static Map<String,String> getErrorMessage(BindingResult bindingResult){

        Map<String,String> map = new HashMap<>();
        for (FieldError fieldError : bindingResult.getFieldErrors()) {

            map.put(fieldError.getField(),fieldError.getDefaultMessage());
        }

        return map;
    }

}
